///////////////////////////////////////////////////////////////////////////////////
//
// ActionScript 3.0 Common Library (MIT License)
// Copyright (c) 2009 AS3CommonCode | Tony Birleffi | http://www.mosaiceye.com
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// The following people are credited with originating all or parts of this code:
// FlashDoctors | flashdoctors.sourceforge.net
//
//////////////////////////////////////////////////////////////////////////////////

package org.as3commoncode.net
{
	import org.as3commoncode.net.AbstractFile;
	import org.as3commoncode.net.IFile;
	import org.as3commoncode.net.QueryString;
	
	/**
	 * The local file class.
	 * 
	 * @see	org.as3commoncode.net.AbstractFile;
	 * @see org.as3commoncode.net.IFile;
	 * 
	 * @author Tony Birleffi
	 */
	public class LocalFile extends AbstractFile implements IFile
	{
		/** * The full path string. */
		public var fullPath:String;
		
		/** * The path string. */
		private var path:String = "";
		
		/** * The filename string. */
		private var filename:String;
		
		/** * The query string. */
		private var queryString:QueryString;
		
		/**
		 * Constructor.
		 * 
		 * @param fullPath	String.
		 */
		public function LocalFile(fullPath:String)
		{
			this.fullPath = fullPath;
			
			// Path.
			var pathSplit:Array = fullPath.split("/");
			var tmpPath:String = "";
			if(pathSplit.length > 1)
			{
				for(var i:Number = 0;i<pathSplit.length;i++)
				{
					if(i>0)
					{
						if((i != pathSplit.length - 1) || (i == pathSplit.length - 1 && String(pathSplit[i]).indexOf(".") < 0))
						{
							tmpPath = tmpPath + "/" + pathSplit[i];
						}
					}
				}
			}
			if(tmpPath != "")
			{
				this.path = tmpPath + "/";
			}
			
			// File and querystring.
			var tmpFile:String = pathSplit[pathSplit.length - 1];
			if(tmpFile.indexOf(".") > -1)
			{
				var fileSplit:Array = tmpFile.split("?");
				this.filename = fileSplit[0];
				
				// QueryString.
				if(fileSplit.length > 1)
				{
					this.queryString = new QueryString(fileSplit[1]);
				}
			}
		}
	    
	    /**
		 * Get the full file path.
		 * 
		 * @return String.
		 */
	    override public function getFullPath():String
		{
			return this.fullPath;
		}
		
		/**
		 * Get the file path.
		 * 
		 * @return String.
		 */
		override public function getPath():String
		{
			return this.path;
		}
		
		/**
		 * Get the filename.
		 * 
		 * @return String.
		 */
		override public function getFilename():String
		{
			return this.filename;
		}
		
		/**
		 * Set the filename.
		 * 
		 * @param s		String path.
		 */
		public function setFilename(s:String):void
		{
			this.filename = s;
		}
		
		/**
		 * Get the query string.
		 * 
		 * @return		QueryString.
		 */
		public function getQueryString():QueryString
		{
			return this.queryString;
		}
		
		/**
		 * Set the query string.
		 * 
		 * @param q		QueryString.
		 */
		public function setQueryString(q:QueryString):void
		{
			this.queryString = q;
		}
	}
}
